package com.mf.controller.basic.webPage;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mf.aspect.debounces.Debounce;
import com.mf.aspect.logApi.LogApi;
import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.utils.UtilConverter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.entity.dto.basic.webPage.DtoPageItem;
import com.mf.entity.req.basic.webPage.ReqPageItem;
import com.mf.service.basic.webPage.ServicePageItem;
import com.mf.entity.req.basic.search.webPage.SearchReqPageItem;

import java.util.List;

/**
 * 前端配置页面明细
 */
@RestController
@RequestMapping("pageItem")
@SaCheckLogin
@Tag(name = "前端配置页面明细")
@Debounce
public class ControllerPageItem {
    @Resource
    private ServicePageItem servicepageItem;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    @SaCheckPermission("page:search")
    public Result<Page<DtoPageItem>> findPage(@RequestBody SearchReqPageItem searchReqPageItem) {
        return Result.success(servicepageItem.findPageByParams(searchReqPageItem));
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission("page:search")
    @PostMapping("/list")
    public Result<List<DtoPageItem>> list(@RequestBody SearchReqPageItem searchReqPageItem) {
        return Result.success(servicepageItem.findListByParams(searchReqPageItem));
    }

    @Operation(summary = "根据页面id查询")
    @GetMapping("findPageItem/{id}")
    public Result<List<DtoPageItem>> findById(@PathVariable Integer id) {
        return Result.success(servicepageItem.findPageItemByPageId(id));
    }

    @Operation(summary = "保存")
    @SaCheckPermission("page:edit")
    @PostMapping("/save")
    @LogApi("保存页面明细")
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqPageItem reqPageItem) {
        servicepageItem.save(UtilConverter.converter(reqPageItem, DtoPageItem.class));
        return Result.success();
    }


    @Operation(summary = "修改")
    @SaCheckPermission("page:edit")
    @LogApi("修改页面明细")
    @PostMapping("/update")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqPageItem reqPageItem) {
        servicepageItem.updateById(UtilConverter.converter(reqPageItem, DtoPageItem.class));
        return Result.success();
    }


    @Operation(summary = "删除")
    @SaCheckPermission("page:delete")
    @LogApi("删除页面明细")
    @GetMapping("/delete/{pageId}/{id}")
    public Result<Void> delete(@PathVariable Integer pageId, @PathVariable Integer id) {
        servicepageItem.deleteById(pageId, id);
        return Result.success();
    }
}
